package com.example.restaurant.dao;

import com.example.restaurant.model.Orders;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.restaurant.service.param.ModifyOrderParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author x
 * @since 2022-09-29
 */
public interface OrderMapper extends BaseMapper<Orders> {
    @Select("select Max(fetch_number)\n" +
            "from `orders`\n" +
            "where \n" +
            "order_time >= STR_TO_DATE(#{date},'%Y-%m-%d')")
    String getMaxCode(String date);
    @Insert("insert into orders (id,order_number,store_id,fetch_number,total_amount,order_time,desk_id,discount,order_status,people_number) values (default,#{order.orderNumber},#{order.storeId},#{order.fetchNumber},#{order.totalAmount},#{order.orderTime},#{order.deskId},#{order.discount},#{order.orderStatus},#{order.peopleNumber})")
    void addOrder(@Param("order") Orders orders);
//    @Select("select order_number,fetch_number,order_time,total_amount from orders where order_number like '%#{number}%'")
//    List<Order> queryOrder(String number);
    @Update("update orders set order_status=#{param.orderStatus} where order_number=#{param.orderNumber}")
    int modifyOrder(@Param("param") ModifyOrderParam param);

    @Select("select * from orders where store_id=1 AND order_status= 'NEW_ORDER'")
    List<Orders> selStatusBySId(@Param("sid") int storeId);
    @Update("update orders set total_amount=#{amount} where order_number=#{number}")
    int modifyTotalAmount (@Param("amount") Long amount,@Param("number") String orderNumber);
}
